package pre.lxm.demo.chart.horizontal;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import pre.lxm.demo.R;
import pre.lxm.demo.chart.bean.RecordBean;

/**
 * Created by lxm on 2017/6/7.
 */

public class HorizontalActivity extends AppCompatActivity {


    @BindView(R.id.horizontal_chartview1)
    HorizontalRecordChartView chartview1;
    @BindView(R.id.horizontal_chartview2)
    HorizontalRecordChartView chartview2;
    @BindView(R.id.horizontal_chartview3)
    HorizontalRecordChartView chartview3;
    @BindView(R.id.chart_linear)
    ChartLinearLayout chartLinear;
    //    @BindView(R.id.btn_refresh)
//    Button btnRefresh;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_horizontal);
        ButterKnife.bind(this);
    }

    @OnClick(R.id.btn_refresh)
    public void btnRefreshClick(View view) {
        chartview1.refreshData(setRecordData(12));
        chartview2.refreshData(setRecordData(12));
        chartview3.refreshData(setRecordData(12));
        chartLinear.getRecordChartView().refreshData(setRecordData(8));
    }

    private List<RecordBean> setRecordData(int size) {
        List<RecordBean> mRecordList = new ArrayList<>();
        String[] results = new String[]{"3", "1", "0"};
        String[] hosts = new String[]{"h", "g"};

        for (int i = 1; i <= size; i++) {
            RecordBean recordBean = new RecordBean();
            recordBean.setTurn(i < 10 ? i + " " : i + "");
            recordBean.setResult(results[new Random().nextInt(3)]);
            recordBean.setIsHost(hosts[new Random().nextInt(2)]);
            mRecordList.add(recordBean);
        }
        return mRecordList;
    }


}
